home *** CD-ROM | disk | FTP | other *** search
-
- Hi - here are the double buffering routines you were interested in.
- They are very easy to use and as far as the memory meter on the Workbench
- title bar, they also return every byte they allocate. I also uploaded this
- to Programming if you don't get the whole thing.
-
- Drawbacks:
-
- a) No message port. You have to roll your own.
- b) No depth arranging. Because I have to to LoadView() to
- display the frame, you can't KEEP it in the background.
- c) More work for the programmer. (not too much though)
-
- Advantages:
-
- a) No screen or windows needed.
- b) Fast - I don't call ReThinkDisplay() or MakeScreen().
- c) SHOULD work with an interlaced display (just add two
- more FreeCprList(bmxSHF)'s into FreedbuffMem()).
- d) It works.
- e) It's free.
-
- I think the advantages outweigh the disadvantages. I hope you have
- fun with them, and if you have any questions don't hesitate to ask.
-
- -Steve-
-
- Quote of the day:
-
- "Dare to be gorgeous and unique. But don't ever be cryptic or otherwise
- unfathomable. Make it unforgettably great."
-
- Intuition Reference Manual, pg 231.
-
- /*************************************************************
- ** **
- ** This program was written by Steve Berry and **
- ** is hereby placed firmly into the public domain. **
- ** In otherwords, don't blame me if it breaks. **
- ** **
- ** File: dbuff.c **
- ** **
- **************************************************************/
-
- #include "exec/types.h"
- #include "exec/exec.h"
- #include "intuition/intuition.h"
- #include "graphics/gels.h"
- #include "graphics/rastport.h"
-
- struct ViewPort vp1;
- struct ViewPort vp2;
- struct RastPort rp;
- struct RasInfo ri;
- struct View view;
-
- struct BitMap bm1;
- struct BitMap bm2;
-
- extern void InitBitMap(),WaitBOVP(),MakeVPort(),LoadView(),InitRastPort();
- extern void InitVPort(),MrgCop(),FreeVPortCopLists(),FreeCprList();
- extern void FreeMem(),InitView();
- extern PLANEPTR AllocMem();
-
- #define PLANESIZE 8000
- #define CHIPCLEAR MEMF_CHIP+MEMF_CLEAR+MEMF_PUBLIC
- #define DEPTH 4
- #define WIDTH 320
- #define HEIGHT 200
-
- struct CopList *bm1LOF,*bm1SHF,*bm2LOF,*bm2SHF;
-
- /*
- *
- * Procedure:
- *
- * Initdbuff();
- * while(not bored){
- * draw into 1
- * Display1()
- * draw into 2
- * Display2();
- * }
- * FreedbuffMem();
- *
- */
-
- Initdbuff()
-
- {
- int i;
-
- for(i=0;i<DEPTH;i++){
- bm1.Planes[i] = AllocMem(PLANESIZE,CHIPCLEAR);
- bm2.Planes[i] = AllocMem(PLANESIZE,CHIPCLEAR);
- }
-
- InitBitMap(&bm1,DEPTH,WIDTH,HEIGHT);
- InitBitMap(&bm2,DEPTH,WIDTH,HEIGHT);
-
- ri.BitMap = &bm1;
- ri.RxOffset = 0; ri.RyOffset = 0;
- ri.Next = NULL;
-
- InitRastPort(&rp);
-
- rp.BitMap = &bm1;
-
- InitVPort(&vp1); InitVPort(&vp2);
-
- vp1.DWidth = WIDTH; vp1.DHeight = HEIGHT; vp1.DxOffset = 0;
- vp1.DyOffset = 0; vp1.RasInfo = &ri; vp1.Next = &vp2;
-
- vp2.DWidth = WIDTH; vp2.DHeight = HEIGHT; vp2.DxOffset = 0;
- vp2.DyOffset = 0; vp2.RasInfo = &ri; vp2.Next = NULL;
-
- InitView(&view);
-
- view.ViewPort = &vp1;
-
- Disp(&view);
-
- bm1LOF = view.LOFCprList;
- bm1SHF = view.SHFCprList;
-
- view.LOFCprList = 0;
- view.SHFCprList = 0;
-
- ri.BitMap = &bm2;
- rp.BitMap = &bm2;
-
- Disp(&view);
-
- bm2LOF = view.LOFCprList;
- bm2SHF = view.SHFCprList;
-
- view.LOFCprList = bm1LOF;
- view.SHFCprList = bm1SHF;
-
- ri.BitMap = &bm1;
- rp.BitMap = &bm1;
- }
-
- /*
- *
- * This function Displays bitplane 1 and
- * set's up for drawing into bitplane 2.
- *
- */
-
- Display1()
- {
- Forbid();
- WaitBOVP(&vp2);
- Disp(&view);
- Permit();
-
- view.LOFCprList = bm2LOF;
- view.SHFCprList = bm2SHF;
-
- ri.BitMap = &bm2;
- rp.BitMap = &bm2;
- }
-
- /*
- *
- * This function Displays bitplane 2 and
- * set's up for drawing into bitplane 1.
- *
- */
-
- Display2()
- {
- Forbid();
- WaitBOVP(&vp1);
- Disp(&view);
- Permit();
-
- view.LOFCprList = bm1LOF;
- view.SHFCprList = bm1SHF;
-
- ri.BitMap = &bm1;
- rp.BitMap = &bm1;
- }
-
- Disp(v)
- struct View *v;
- {
-
- MakeVPort(v,&vp1);
- MakeVPort(v,&vp2);
- MrgCop(v);
- LoadView(v);
-
- }
-
- /* got to free up space on the other bitmap */
-
- FreedbuffMem()
- {
- int i;
- for(i=0;i<DEPTH;i++)
- FreeMem(bm1.Planes[i],PLANESIZE);
- for(i=0;i<DEPTH;i++)
- FreeMem(bm2.Planes[i],PLANESIZE);
-
- FreeVPortCopLists(&vp1);
- FreeVPortCopLists(&vp2);
- FreeCprList(bm1LOF); /* should do FreeCpr for SHF if LACE */
- FreeCprList(bm2LOF);
- }